package com.rayo.accesscontrollercopy.module.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.github.johnkil.print.PrintView;
import com.rayo.accesscontrollercopy.R;
import com.rayo.accesscontrollercopy.model.db.bean.KeyData;
import com.rayo.accesscontrollercopy.utils.TimeFormatUtil;

import java.util.HashMap;
import java.util.List;


/**
 * Created by lyc-pc on 17/2/23.
 */

public class KeyAdapter extends RecyclerView.Adapter<KeyAdapter.KeyViewHolder> {
    private Context mContext;
    private List<KeyData> mList;
    private OnClicker mOnClicker;

    public KeyAdapter(List<KeyData> mList, Context context) {
        this.mList = mList;
        mContext = context;

    }

    @Override
    public KeyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new KeyViewHolder(LayoutInflater.from(mContext).inflate(R.layout.adapter_key, parent, false));
    }

    @Override
    public void onBindViewHolder(KeyViewHolder holder, final int position) {
        KeyData keyData = mList.get( position);
        if (keyData.getState()==0){
            holder.mPvAdapterKeyKeyinfoError.setVisibility(View.VISIBLE);
//            holder.mLinearLayout.setVisibility(View.INVISIBLE);
//            holder.mTvAdapterKeyKeyinfounbind.setVisibility(View.INVISIBLE);
        }else {
            holder.mPvAdapterKeyKeyinfoError.setIconText(mContext.getString(R.string.ic_key));
            holder.mPvAdapterKeyKeyinfoError.setIconColor(mContext.getResources().getColor(R.color.Indigo));
        }
//        if (keyData == null) {
//            holder.mPvAdapterKeyKeyinfoError.setVisibility(View.VISIBLE);
//            holder.mLinearLayout.setVisibility(View.INVISIBLE);
//            holder.mTvAdapterKeyKeyinfounbind.setVisibility(View.INVISIBLE);
//        } else {
//            holder.mPvAdapterKeyKeyinfoError.setVisibility(View.GONE);
//            holder.mLinearLayout.setVisibility(View.VISIBLE);
//            holder.mTvAdapterKeyKeyinfounbind.setVisibility(View.VISIBLE);
//            holder.mTvAdapterKeyKeyinfoSerialnumber.setText(mContext.getString(R.string.serialnumber) + keyData.getSerialnumber());
//            holder.mTvAdapterKeyKeyinfoTagid.setText(mContext.getString(R.string.tag_id) + keyData.getTagid());
//            holder.mTvAdapterKeyKeyinfoTime.setText(mContext.getString(R.string.key_time) + TimeFormatUtil.showDateTime(mContext, keyData.getTime()));
//            holder.mTvAdapterKeyKeyinfoVersion.setText(mContext.getString(R.string.key_version) + keyData.getVersion());
//        }
        if (mOnClicker != null) {
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mOnClicker.click(v,position);
                }
            });
        }

    }

    public void setOnClicker(OnClicker onClicker) {
        mOnClicker = onClicker;
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    static class KeyViewHolder extends RecyclerView.ViewHolder {


        PrintView mPvAdapterKeyKeyinfoError;


        public KeyViewHolder(View itemView) {
            super(itemView);
            mPvAdapterKeyKeyinfoError = (PrintView) itemView.findViewById(R.id.pv_adapter_key_keyinfo_error);
        }
    }


}
